

function treeMenu(a)
{
    this.tree=a||[];
    this.groups={};
};

treeMenu.prototype={

    init:function(parentId)
    {
        this.group();
        var treeData=[{
		    "id" : "-1",
		    "text" : "全部",
		    "name" : "全部",
		    'state': {
                'opened': true
            },
		    "children" :this.getDom(this.groups[parentId])
        }];
        return treeData;
    },
    group:function()
    {
    	
        for(var i=0;i<this.tree.length;i++)
        {
        	if(!this.tree[i].parentMenu){
        		this.tree[i].parentMenu={id:0}
        	}
        	
            if(this.groups[this.tree[i].parentMenu.id])
            {
                this.groups[this.tree[i].parentMenu.id].push(this.tree[i]);
            }
            else
            {
                this.groups[this.tree[i].parentMenu.id]=[];
                this.groups[this.tree[i].parentMenu.id].push(this.tree[i]);
            }
        }
    },
    
    getDom:function(a){
        if(!a){return ''}
        var arr=[]
		var root = {};
        for(var i=0;i<a.length;i++)
        {
        	root={
			    "id" : a[i].id,
			    "text" : a[i].name,
			    "name" : a[i].name
			  };
			var temp=this.groups[a[i].id];
			root["children"]=this.getDom(temp);
          	arr.push(root);
        };
        return arr;
    }
};